<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<meta charset="UTF-8">
		<title>用户中心-修改登录密码</title>
		<script src="/v3/js/jquery-1.10.2.min.js" type="text/javascript"></script>		
		<link type="text/css" rel="stylesheet" href="/v3/css/wstyle.css">
		<link type="text/css" rel="stylesheet" href="/v3/css/account.css">
	</head>
<style>
</style>
	<body>
<div id="wrap">
  <div class="change-passwd">
    <div class="link-touch">
      <ul class="items">
        <li>
          <label class="txt">原密码</label>
          <input type="password" class="input" id="pwd"  maxlength="16" placeholder="请输入您的登录密码">
        </li>
      </ul>
    </div>
    <div class="link-touch">
      <ul class="items">
        <li>
          <label class="txt">新密码</label>
          <input type="password" class="input" id="newPwd"  maxlength="16" placeholder="请输入新密码">
        </li>
        <li>
          <label class="txt">确认密码</label>
          <input type="password" class="input" id="confirmnewPwd" maxlength="16" placeholder="请再次输入新密码">
        </li>
      </ul>
      <div id ="errorTip" class="vtip errs"></div>
    </div>
    <div class="Nxt-btn"> <a href="javascript:modifyLoginPassword();">修改密码</a> </div>
  </div>
</div>
		<jsp:include page="/include/v3/footer.jsp"></jsp:include>
<script type="text/javascript">
    function confirmPsd(value){
    	if(value !=""&& value.length <6 || value.length > 16){
    		$("#errorTip").html("密码长度为6-16位").show();
    		return false;
    	}else if(value == ""){
    		$("#errorTip").html("请输入密码").show();
    		return false;
    	}else{
    		return true;
    	}
    }
    
    function isOldSameToNew(){
    	if($("#pwd").val() == $("#newPwd").val()){
    		$("#errorTip").html("新密码与现在密码不能相同").show();
    		return false;
    	}
    	else{
    		return true;
    	}
    }
    
    function confirmSame(){
    	if($("#newPwd").val() == $("#confirmnewPwd").val()){
    		return true;
    	}else{
    		$("#errorTip").html("两次新密码不一致").show();
    		return false;
    	}   	
    }
    
    function invalidate(){
    	if(confirmPsd($("#pwd").val()) && confirmPsd( $("#newPwd").val()) && confirmPsd($("#confirmnewPwd").val()) && isOldSameToNew() && confirmSame()){
    		return true;
    	}else{
    		return false;
    	}
    }
    
    function modifyLoginPassword(){
    	if(invalidate()){
    		var param = {};
            param["paramMap.oldPassword"] = $("#pwd").val();
            param["paramMap.newPassword"] = $("#newPwd").val();
            param["paramMap.confirmPassword"] = $("#confirmnewPwd").val();
    		$.ajax({
    			type:'POST',
    			url: environment.basePath+"/updateLoginPsdWithNoForward.do",
    			//data:{
    			//	"pwd": encodeData("10001", "a853d232483a2102f795f7f52da9dfa5515d61fa2b2b7fc671a1036a587eb2903a85574de966490e76194a6fabf39457915ea69519d88c8c58695e49dbcd3b37f9ac2cf2d97f89b62be9c54361f75457df6193c75a0080510d28f3402c7cf6704c99ce2c17f5b1bf5d84fe0317be120d6295b6f08ab21b264f1fa0aca31b3c0b", "974", $("#pwd").val()),
    			//	"newPwd": encodeData("10001", "a853d232483a2102f795f7f52da9dfa5515d61fa2b2b7fc671a1036a587eb2903a85574de966490e76194a6fabf39457915ea69519d88c8c58695e49dbcd3b37f9ac2cf2d97f89b62be9c54361f75457df6193c75a0080510d28f3402c7cf6704c99ce2c17f5b1bf5d84fe0317be120d6295b6f08ab21b264f1fa0aca31b3c0b", "974", $("#newPwd").val())
    			//},
    			data: param,
    			success: function(data){
    				if(data.code == 1){
    					window.location.href="/modifyLoginPwdSuccess.do";
    				}else if(data.code <=0){
    					$("#errorTip").html(data.msg).show();
    				}else{
    					$("#errorTip").html("登录密码更新出错,请重新修改").show();
    				}
    			},
    			error: function(data){
    				$("#errorTip").html("登录密码更新出错,请重新修改").show();
    			} 
    		});
    	}
    }
</script>
	</body>
</html>
